package shop.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import shop.dao.GoodsDao;
import shop.dao.impl.GoodsDaoImpl;
import shop.entity.Goods;

@WebServlet("/GoodsServlet")
public class GoodsServlet extends BaseServlet {
	private GoodsDao dao = new GoodsDaoImpl();
	//查询首页要显示的热门商品
	public void findAll(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession();
		List<Goods> list = dao.findAll();
		session.setAttribute("list", list);
		response.sendRedirect("index.jsp");
	}
	
	//查询商品详情
	public void findOne(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession();
		int id = Integer.parseInt(request.getParameter("id"));
		Goods goods = dao.findById(id);
		session.setAttribute("goods", goods);
		response.sendRedirect("product.jsp");
	}


}
